Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to pyproject.toml #203

Merged
merged 27 commits into from
Oct 24, 2023
Merged

Conversation

jGaboardi
Copy link
Member

This PR resolves #200 and performs more rigorous linting, clean up, etc. Also, with added doctesting coverage goes up to 88%.

@codecov
Copy link

codecov bot commented Oct 18, 2023

Codecov Report

Merging #203 (3e62357) into main (711fa81) will increase coverage by 17.2%.
The diff coverage is 74.6%.

Impacted file tree graph

@@           Coverage Diff            @@
##            main    #203      +/-   ##
========================================
+ Coverage   70.5%   87.8%   +17.2%     
========================================
  Files         16       9       -7     
  Lines       1880    1429     -451     
  Branches     288       0     -288     
========================================
- Hits        1326    1254      -72     
+ Misses       530     175     -355     
+ Partials      24       0      -24     
Files Coverage Δ
giddy/__init__.py 100.0% <100.0%> (ø)
giddy/components.py 93.2% <100.0%> (+79.5%) ⬆️
giddy/ergodic.py 96.3% <100.0%> (+3.6%) ⬆️
giddy/mobility.py 93.1% <ø> (+10.3%) ⬆️
giddy/rank.py 98.4% <100.0%> (+43.7%) ⬆️
giddy/sequence.py 100.0% <100.0%> (+2.6%) ⬆️
giddy/util.py 100.0% <100.0%> (+2.9%) ⬆️
giddy/directional.py 87.0% <50.0%> (+31.0%) ⬆️
giddy/markov.py 77.4% <57.6%> (+21.7%) ⬆️

... and 7 files with indirect coverage changes

@jGaboardi jGaboardi requested a review from weikang9009 October 18, 2023 22:37
giddy/markov.py Outdated
@@ -300,7 +301,7 @@ def sojourn_time(self):
return self._st


class Spatial_Markov(object):
class Spatial_Markov: # noqa N801 – Class name should use CapWords convention
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving these comments in the code base does not seem to be the best idea. What is the best practice to "resolve" these comments? @jGaboardi

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of comment (# noqa N801) is pretty standard practice for instances to ignore. I put the explanation in there for your information; it can be deleted.

Long term, the best solution is to update all class names to use CapWords-style (e.g. SpatialMarkov), but that would break a ton of stuff in the giddy API by doing that now.

Perhaps we can get @knaaptime's and @martinfleis's advice here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd ignore them in pyproject. Then you don't need these comments.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable considering the circumstances. I'll update this PR @weikang9009.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've update the PR and move most of the # noqa ### to the pyproject.toml where they are connected with specific files. I do think it is important to keep the # noqa E501 (line too long) in place to cap lines at the desired length where possible. @weikang9009 but since you are the giddy BDFL if you don't think that's a good idea, I will move those, too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • There is, but seems to be convoluted and way too much effort, I'd vote for keeping the # noqa E501 here.
  • I explored this one and found that I would either be very difficult or not possible. I'd also vote for keeping noqa UP031 in here, too. Or I can add UP031 to to pyproject.toml to ignore specifically in markov.py. Would that be a good compromise?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move both E501 and UP031 to pyproject.toml since there are no easy ways to address them at the moment?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving UP031 is reasonable since it happens only in 1 file, we know where it happens, and it is not likely to happen anywhere else (creating strings of .tex files). However, long lines is something much more common and very much affects readability. Generally, this is a trivial thing to fix in code, comments, and docstrings. But the offending lines here are actual print outs within doctests (in ergodic.py, markov.py, and sequence.py). The means the actual print commands need to change for a "proper fix".

In terms of what I would recommend in order of (what I see as) best practice:

  1. Keep the # noqa E501 at the end of offending docstrings. It's what ruff recommends.
  2. Change the print statements in the code base so that no line is longer than our enforced length. This "fixes" the line length issue, but then were are changing actual code to fix something in a doctest print out. It doesn't feel right to me.
  3. Add a global # noqa E501 in pyproject.toml only for ergodic.py, markov.py, and sequence.py. Since black also handles line length, this takes care of many offenders but not all (black has a tough time with long strings).

So, I've said my piece 😆 and I will defer to your judgement @weikang9009. Will it be 1, 2, or 3? Whichever you choose, I will implement here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the current cases of # noqa E501 are long lines that are error messages in the docstrings. I am unsure whether there is a way to make them conform to the 79-character rule. Any thoughts?

See https://github.com/geopandas/geopandas/blob/e5bcf27c157b483ead2a7e63a280bf90489762c4/geopandas/geodataframe.py#L538-L549 on how it can be done with a little effort. Alternatively, we could keep the local # noqa E501 there. We can also just ignore E501 and add it to pyproject but the fix seems easy enough.

there are a bunch of noqa UP031 in markov.py that are used for outputting a latex table. I have explored a bit, and I am not sure how to make them conform to the printf-string-formatting rule.

I'd just keep the # noqa there .

Change the print statements in the code base so that no line is longer than our enforced length. This "fixes" the line length issue, but then were are changing actual code to fix something in a doctest print out. It doesn't feel right to me.

No, we should not enforce line breaks in prints/warnings to conform to a rule we impose on our code. It can look weird in notebooks etc.

My proposal is to fix the line lengths with a line break as shown in the geopandas example and keep # noqa UP031 in the code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the geopandas example @martinfleis! I was able to fix those long lines (just pushed the commit that fixes them to this PR).

@jGaboardi Let's go with your option 1. Thank you so much!

@weikang9009 weikang9009 merged commit 7496b86 into pysal:main Oct 24, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

swap out setup.py for pyproject.toml
3 participants